
var easyUi = new Object();
var easyUiButtons;
var linkButtons = new Array();
linkButtons["add"] = {text: '添加',iconCls: 'icon-add',handler: function () {addFun();},plain:true};
linkButtons["edit"] = {text: '修改',iconCls: 'icon-edit',handler: function () {editFun();},plain:true};
linkButtons["remove"] = {text: '删除',iconCls: 'icon-remove',handler: function () {removeFun();},plain:true};
linkButtons["refresh"] = {text: '刷新',iconCls: 'icon-refresh',handler: function () {removeFun();},plain:true};
linkButtons["save"] = {text: '保存',iconCls: 'icon-save',handler: function () {saveFun();},plain:true};
linkButtons["rest"] = {text: '重置',iconCls: 'icon-save',handler: function () {removeFun();},plain:true};


linkButtons["setting"] = {text: '编辑',iconCls: 'icon-i-edit',handler: function () {removeFun();},plain:true};






function getLinkButtons (buttons) {
	
	var result = new Array();
	
	
	for (var i=0;i<buttons.length;i++) {
		
		var button = linkButtons[buttons[i].name];
		
		if (buttons[i].handler!=undefined) {
			button.handler= buttons[i].handler;
		}
		if (buttons[i].text!=undefined) {
			button.text= buttons[i].text;
		}
		if(buttons[i].iconCls!=undefined) {
			button.iconCls= buttons[i].iconCls;
		}
		result[i] = button;
	}
	
	return result;
}

easyUi.getButton = function (panel,button,func) {
	
	linkButtons[button].handler=func;
	$('#'+panel).linkbutton(linkButtons[button]);
};

easyUi.initButton = function (buttons) {
	
	easyUiButtons = getLinkButtons(buttons);
	for (var i in easyUiButtons) {
		var id = 'b_'+easyUiButtons[i].id+i;
		easyUiButtons[i].id = id;
	}
	return easyUiButtons;
};

easyUi.initButtonBar = function (panel,buttons) {
	
	var result = new Array();
	easyUiButtons = getLinkButtons(buttons);

	for (var i in easyUiButtons) {
		var id = 'bb_'+easyUiButtons[i].id+i;
		$('#'+panel).html($('#'+panel).html()+'<a id="'+id+'"></a>');
		easyUiButtons[i].id = id;
		result[i]=easyUiButtons[i];
	}
//	alert($('#'+panel).html());
	$.each (result,function (i){
		
		$('#'+result[i].id).linkbutton(result[i]);
		$('#'+result[i].id).click(eval(result[i].handler));
	});
	
};

easyUi.grid = function (page,panel,buttons){

};

easyUi.form = function (panel,obj) {
	
	$('#'+panel).panel({
		
		title : 'formTest',
		iconCls : 'icon-remove',
		collapsible : true,
		minimizable : true,
		maximizable : true,
//				closable : true,
//				collapsed : true,
//				minimized : true,
//				maximized : true,
//				closed : true,

	});
	
};

easyUi.buttonBar = function () {
	
	alert("buttonBar");
};

easyUi.filterBar = function () {
	
	alert("buttonBar");
};



easyUi.dataGridToForm = function (dataGridId,formId,prefix) {
	
	var selected = $(dataGridId).datagrid('getSelected');
	
	easyUi.loadForm(formId,selected,prefix);
};

easyUi.loadForm = function (formid,row,prefix) {
	var data = {};
	if (prefix == undefined) {
		
		$(formid).form("load", row);
	}else {
		
		$.each(row, function(name, value) {
			data[prefix + name] = value;
		});
		$(formid).form("load", data);
	};
	
};




//-------------------------
//初始化


